<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>user_manage</title>
    <link rel="stylesheet" href="/static/css/index.css">
    <link rel="stylesheet" href="/static/css/borrow_list.css">
    <script type="text/javascript" src="/static/js/jquery-1.7.2.js"></script>
    <script>
        $(function (){
            $(".reviseUser").change(function (){
                var userId = $(this).attr("id");
                var password = $(this).val();
                //后端传来的判断，该用户是否存在
                $.ajax({
                   url:"/reviseUser",
                    method:"GET",
                    data:{
                        userId:userId,
                        password:password
                    },
                    success:function (response){
                        if(response=="用户不存在"){
                            alert("用户不存在");
                        }else{
                            location="/reviseUser?userId="+userId+"&password="+password;
                        }
                    },
                    error:function (xhr, status, error){
                        alert("发生错误：" + error);
                    }
                });
            });
            $(".deleteUser").click(function (){
                var userId = $(this).attr("id");
                $.ajax({
                    url:"/deleteUser",
                    method:"GET",
                    data:{
                        userId:userId
                    },
                    success:function (response){
                        if(response=="用户不存在"){
                            alert("用户不存在");
                        }
                    },
                    error:function (xhr, status, error){
                        alert("发生错误：" + error);
                    }
                });
            });

        });
    </script>
</head>
<body>
<div class="header">
    <div>用户管理</div>
    <div>
        <a href="/logout">注销</a>
        <a href="/getBookByPage">图书管理</a>
        <a href="/main">返回</a>
    </div>
</div>
<div id="main">
    <div class="borrow_record">
        <table>
            <tr>
                <td>用户名</td>
                <td>用户密码</td>
                <td>用户类型</td>
                <td>手机号</td>
                <td>邮箱</td>
                <td>创建时间</td>
                <td>操作</td>
            </tr>
            {{range .}}
                <tr>
                    <td>{{.Username}}</td>
                    <td><input id="{{.Id}}" class="reviseUser" type="text" value="{{.Password}}"></td>
                    <td>{{.Usertype}}</td>
                    <td>{{.Phone}}</td>
                    <td>{{.Email}}</td>
                    <td>{{.CreateTime}}</td>
                    <td><a href="/deleteUser?userId={{.Id}}" id="{{.Id}}" class="deleteUser">删除</a></td>
                </tr>
            {{end}}
        </table>
    </div>
</div>
</body>
</html>